package com.seuic.hnjiningposapp.hnapps.ui.view.dialog;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.ToastUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.lxj.xpopup.core.BasePopupView;
import com.seuic.hnjiningposapp.R;
import com.seuic.hnjiningposapp.hnapps.bean.ZzhBean;
import com.seuic.hnjiningposapp.hnapps.util.GetMoneyLvUtils;
import com.socks.library.KLog;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * 定转活 子账户信息
 */
public class DtoHClientinfoPp extends BasePopupView {
    Unbinder bind;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;

    Context mContext;
    SelDtoHlist mSelDtoHlist;

    List<ZzhBean> zzhBeans = new ArrayList<>();

    public DtoHClientinfoPp(@NonNull Context context, SelDtoHlist selDtoHlist) {
        super(context);
        this.mContext = context;
        this.mSelDtoHlist = selDtoHlist;
    }

    public List<ZzhBean> getZzhBeans() {
        return zzhBeans;
    }

    public void setZzhBeans(List<ZzhBean> zzhBeans) {
        this.zzhBeans = zzhBeans;
    }

    @Override
    protected int getPopupLayoutId() {
        return R.layout.dtoh_clientinfo_pp_layout;
    }


    @Override
    protected void onCreate() {
        super.onCreate();
        bind = ButterKnife.bind(this);
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        Adapter adapter = new Adapter(R.layout.dto_hclentinfo_rv_item_layout, null);
        recyclerView.setAdapter(adapter);

        recyclerView.addItemDecoration(new DividerItemDecoration(mContext, DividerItemDecoration.VERTICAL));

        KLog.e(zzhBeans.size());

        adapter.setNewData(zzhBeans);



    }

    @Override
    protected void onDismiss() {
        super.onDismiss();
        //注解解绑
        if (bind != null && bind != Unbinder.EMPTY) {
            bind.unbind();
        }
        this.bind = null;
    }

//    @OnClick(R.id.next_btn)
//    public void onViewClicked() {
//
//

//
//        mSelDtoHlist.SelDtoHData();
//    }

    private class Adapter extends BaseQuickAdapter<ZzhBean, BaseViewHolder> {


        public Adapter(int layoutResId, @Nullable List<ZzhBean> data) {
            super(layoutResId, data);
        }

        @Override
        protected void convert(@NotNull BaseViewHolder baseViewHolder, ZzhBean zzhBean) {
            TextView pen_tv, name_tv, open_money, user_money, save_time, in_tv, start_time, end_time;
            pen_tv = baseViewHolder.findView(R.id.item_pentv);//笔号
            name_tv = baseViewHolder.findView(R.id.item_name);//产品名称
            open_money = baseViewHolder.findView(R.id.item_open_money);//开户金额
            user_money = baseViewHolder.findView(R.id.item_usermoney);//可用余额
            save_time = baseViewHolder.findView(R.id.item_save_time);//存期
            in_tv = baseViewHolder.findView(R.id.item_in);//利率
            start_time = baseViewHolder.findView(R.id.item_start_time);//开始时间
            end_time = baseViewHolder.findView(R.id.item_endtime);//结束时间

            //笔号
            pen_tv.setText("笔号" + zzhBean.getFS_SEQ_NO().trim());

            //名称
            name_tv.setText(zzhBean.getSA_PDP_NAME().trim());

            //开户金额
            //开户金额
            //开户金额
            //去掉0
            if (zzhBean.getFS_OPAC_AMT().trim().equals("000000000000000")) {
                open_money.setText("0.00");
            } else {
                open_money.setText(GetMoneyLvUtils.getMoney(zzhBean.getFS_OPAC_AMT()));
            }
            //账户余额
            //账户余额
            //账户余额
            //去掉0

            if (zzhBean.getFS_ACCT_BAL().equals("000000000000000")) {
                user_money.setText("0.00");
            } else {

                user_money.setText(GetMoneyLvUtils.getMoney(zzhBean.getFS_ACCT_BAL()));
            }
            //存期
            save_time.setText(zzhBean.getFS_DEP_PRD().trim().replaceFirst("^0*", "") + "天");

            //利率
            //利率

            in_tv.setText(GetMoneyLvUtils.getLv(zzhBean.getFS_INTR()));


            //开户日期
            start_time.setText(GetMoneyLvUtils.gettimeNohour(zzhBean.getFS_OPAC_DT().trim()));

            //到期日期
            end_time.setText(GetMoneyLvUtils.gettimeNohour(zzhBean.getFS_DUE_DT().trim()));


            Button tbtn = baseViewHolder.findView(R.id.t_btn);
            tbtn.setOnClickListener(v -> {
                mSelDtoHlist.SelDtoHData(zzhBean);
            });
        }
    }

    public interface SelDtoHlist {
        //添加返回数据   金额
        void SelDtoHData(ZzhBean zzhBean);
    }

}
